package com.Blog.www.dao.Impl;

import com.Blog.www.dao.LikeDao;
import com.Blog.www.po.UserLike;
import com.Blog.www.utils.SqlDao;

import java.util.List;


/**
 * 用户收藏实现类
 *
 * @author 君未洋
 */
public class LikeDaoImpl implements LikeDao {

    private static SqlDao dao = new SqlDao();

    @Override
    public Boolean add(String uid, String bid) {
        String sql = "insert into userlike values (null,?,?)";
        return dao.update(sql, uid, bid);
    }

    @Override
    public Boolean delete(String uid, String bid) {
        String sql = null;
        if (uid == null && bid != null) {

            sql = "delete from userlike where blogid =?";
            return dao.update(sql, bid);
        } else if (bid == null && uid != null) {
            sql = "delete from userlike where userid =?";
            return dao.update(sql, Integer.parseInt(uid));
        } else {
            sql = "delete from userlike where userid =? and blogid =?";
            return dao.update(sql, uid, bid);
        }

    }

    @Override
    public boolean findLike(int uid, int bid) {
        String sql = "select count(*) as count from userlike where userid=? and blogid=?";
        Integer i = dao.selectUserLike(sql, uid, bid);
        if (i > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public List<UserLike> findLike(int id) {
        String sql = "select * from userlike where userid = ?";
        return dao.selectLike(sql, id);

    }
}
